﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule.MasterData;
using Jumpton.SFA.Server.Entity;
using Jumpton.SFA.Server.BusinessRule;
using Jumpton.SFA.Server.BusinessRule.InStoreDataMeasures;
using Jumpton.Persistent;
using Jumpton.SFA.Server.BusinessRule.CallRoute;

public partial class CallRoute_Visit_KPI_List_View : PageBase
{
    private decimal id = 0;
    private const string CHANNEL_ID = "id";
    private decimal visitid = 0;
    private const string VISIT_ID = "visitid";
    private string NAME = "";
    private string USERNAME = "";
    private string VISITTIME = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString[CHANNEL_ID] != null)
        {
            decimal.TryParse(Request.QueryString[CHANNEL_ID], out id);
        }
        if (Request.QueryString[VISIT_ID] != null)
        {
            decimal.TryParse(Request.QueryString[VISIT_ID], out visitid);
        }
        NAME = Request.QueryString["name"];
        USERNAME = Request.QueryString["username"];
        VISITTIME = Request.QueryString["visittime"];

        if (!IsPostBack)
        {
            GetVisitKPIBy();
            lblVisitHistoryMessage.Text = "[门店名称:  " + NAME + "]" + "      [巡店督导:  " + USERNAME + "]" + "      [拜访时间:  " + VISITTIME + "]";
        }
    }


    public void GetVisitKPIBy()
    {
        DataSet ds = new DataSet();
        ds = RouteManager.SelectKPIByVisit(visitid, MyStateManager.DomainID,1000);

        if (ds != null && ds.Tables.Count > 0)
        {
            for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
            {
                BoundField nameBoundField = new BoundField();
                nameBoundField.DataField = ds.Tables[1].Rows[i]["FieldName"].ToString();
                nameBoundField.HeaderText = ds.Tables[1].Rows[i]["MeasurementName"].ToString();
                gvCPR.Columns.Add(nameBoundField);
            }
            gvCPR.DataSource = ds.Tables[0];
            gvCPR.DataBind();
        }
        else
        {
            gvCPR.DataSource = null;
            gvCPR.DataBind();
        }
    }
}
